package com.sgb.kjwl.repository.impl;

import com.sgb.kjwl.model.api.ApiSource;
import com.sgb.kjwl.model.api.PreferenceSource;
import com.sgb.kjwl.model.entity.AddShoppingCar;
import com.sgb.kjwl.model.entity.DeleteShoppingCar;
import com.sgb.kjwl.model.entity.ShoppingCarEntity;
import com.sgb.kjwl.model.entity.user.AddressEntity;
import com.sgb.kjwl.repository.ShopCompanyInfoRepertory;
import com.sgb.kjwl.repository.ShoppingCarRepertory;
import com.swgk.core.base.api.BaseApiSource;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.base.model.preference.BasePreferenceSource;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.Observable;
import okhttp3.MediaType;
import okhttp3.RequestBody;

public class ShopCompanyInfoRepertoryImpl extends BaseRepertoryImpl implements ShopCompanyInfoRepertory {
    private ApiSource apiSource;
    private PreferenceSource preferenceSource;

    public ShopCompanyInfoRepertoryImpl(BaseApiSource apiSource, BasePreferenceSource preferenceSource) {
        super(apiSource, preferenceSource);
        this.apiSource = (ApiSource) apiSource;
        this.preferenceSource = (PreferenceSource) preferenceSource;
    }

    @Override
    public Observable<BaseEntity<List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>>>> getAddress() {
        return apiSource.getAddress().compose(rxSchedulerHelper());
    }

    @Override
    public Observable<BaseEntity<List<String>>> uploadMutiFile(List<File> fileList) {
        Map<String, RequestBody> photos = new HashMap<>();
        int i = 0;
        for (File file : fileList) {
            RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file);
            photos.put("file" + "\"; filename=\"" + i + "image.jpg\"", requestBody);
            i++;
        }
        return apiSource.uploadMutiFile(photos).compose(rxSchedulerHelper());
    }
}
